<?php

/*
 * This file is part of importXMPmeta.

  importXMPMeta is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  importXMPMeta is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with importXMPMeta.  If not, see <http://www.gnu.org/licenses/>
 * 
 * importXMPMeta
 * V 1.0 - february 2012
 * Copyright Eric Zapletal (http://code.google.com/p/xmputils/)
 * 
 */

/*
 * custom.php : edit customizeLegend() function, $customLegendTextStyle and
 * $customLegendAlignment to create
 * your own personnalized image legends from XMP metadata
 */

$customLegendTextStyle = "Légende";
$customLegendAlignment = "1";

// Convert day/month names to locale
$week = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
$semaine = array("lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche");
$year = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$annee = array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");


/*
 * modify this function to create the image legend from the XMP metadata
 */
function customizeLegend($xmpmeta) {

    global $week;
    global $semaine;
    global $year;
    global $annee;

    // extract dc:description XMP property
    if ($xmpmeta->DoesPropertyExist(SXMPMeta::kXMP_NS_DC, "dc:description[1]"))
        $descInfo = $xmpmeta->GetProperty(SXMPMeta::kXMP_NS_DC, "dc:description[1]") . " ";
    else
        $descInfo = "";

    // extract exif:DateTimeOriginal property
    $dateInfo = "";
    if ($xmpmeta->DoesPropertyExist(SXMPMeta::kXMP_NS_EXIF, "exif:DateTimeOriginal")) {
        $createDate = $xmpmeta->GetProperty(SXMPMeta::kXMP_NS_EXIF, "exif:DateTimeOriginal");

        $dateTime = DateTime::createFromFormat("Y-m-d*H:i:s", $createDate);
        if ($dateTime == null) {
            $dateTime = DateTime::createFromFormat("Y-m-d*H:i", $createDate);
        }

        if ($dateTime != null) {
            $dateInfo = "Le "
                    . str_replace($week, $semaine, $dateTime->format("l")) . " "
                    . $dateTime->format("j") . " "
                    . str_replace($year, $annee, $dateTime->format("F")) . " "
                    . $dateTime->format("Y") . " "
                    . "à " . $dateTime->format("H\hi") . "."
            ;
        }
    }

    return $descInfo . $dateInfo;
}

?>
